from time import sleep

from selenium.webdriver.common.by import By

from page.focus_project_page import FocusProjectPage
import random as r
from page.common_tools import CommonTools


class FocusArticlePage(FocusProjectPage, CommonTools):

    def publish_article(self):
        self.find_button("发布").click()
        self.find_static_text("请输入标题", contains_flag=1).click()
        self.find_static_text("请输入标题", contains_flag=1).send_keys("App面授文章自动化测试%d" % r.randint(100, 999))
        self.find_static_text('请选择').click()
        self.find_static_text('按班级').click()
        # self.swipe(369,645,369,645)  #确定
        self.find_static_text(string="确定",contains_flag=1).click()
        self.find_static_text('请输入描述', contains_flag=1).click()
        self.find_static_text('请输入描述', contains_flag=1).send_keys("这是文章的内容。内容丰富而且有好多名人歌词短文都收录在此文章中，大家可以借鉴与学习，来提高自己的文章水平。这是文章的内容。内容丰富而且有好多名人歌词短文都收录在此文章中，大家可以借鉴与学习，来提高自己的文章水平。")
        self.hide_keyboard()
        self.find_button('附件').click()
        # self.find_button('tupian2').click()
        # self.select_from_album(3)
        self.find_button('xiangji').click()
        self.take_ptoto()
        self.find_button('确认').click()
        sleep(1)
        self.find_static_text("我发布的",contains_flag=1).click()
        sleep(0.5)
        self.swipe_dr("down")
        sleep(1)
        self.swipe(191,200,191,200)  #找到我发布的第一个作品
        sleep(1)
        self.find_button(string="more",contains_flag=1).click()
        self.find_button(string="编辑",contains_flag=1).click()
        self.find_button(string="确认",contains_flag=1).click()
        sleep(2)
        self.find_static_text("管理员发布的", contains_flag=1).click()
        sleep(0.5)
        self.swipe_dr("down")
        self.find_static_text("专家发布的", contains_flag=1).click()
        sleep(0.5)
        self.swipe_dr("down")
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="数学班", contains_flag=1).click()



if __name__ == "__main__":
    test = FocusArticlePage()
    test.enter_project()
    test.enter_tools("文章")
    test.publish_article()
